export function createWebSocket(url, onMessage) {
    const socket = new WebSocket(url);

    socket.onopen = () => {
        console.log('WebSocket connected');
    };

    socket.onmessage = (event) => {
        if (onMessage) onMessage(JSON.parse(event.data));
    };

    socket.onclose = () => {
        console.log('WebSocket disconnected');
    };

    socket.onerror = (error) => {
        console.error('WebSocket error:', error);
    };

    return socket;
}